package com.tanhua.management.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.VideoInfoMapper;
import com.tanhua.common.pojo.VideoInfo;
import com.tanhua.dubbo.server.pojo.Video;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.management.api.VideoManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * Create By Administrator on 2021/7/13.
 */
@Service(version = "1.0.0")
public class VideoManageImp implements VideoManage {


    @Autowired
    private VideoInfoMapper videoInfoMapper;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public PageInfo<VideoInfo> queryVideoInfoList(Integer page, Integer pageSize) {

        PageInfo<VideoInfo> pageInfo = new PageInfo<>();

        QueryWrapper<VideoInfo> queryWrapper = new QueryWrapper<>();

        List<VideoInfo> videoInfos = this.videoInfoMapper.selectList(queryWrapper);

        pageInfo.setPageNum(page);
        pageInfo.setPageSize(pageSize);
        pageInfo.setRecords(videoInfos);
        pageInfo.setTotal(videoInfos.size());

        return pageInfo;
    }


    @Override
    public Video queryVideoByVideo(String videoId){
        Query query = new Query();
        Video video = this.mongoTemplate.findOne(query, Video.class, "id" + videoId);
        if (ObjectUtil.isEmpty(video)){
            return null;
        }
        return video;
    }

}
